<?php
/**
 * 作品展示分类列表
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package 古槐乡情
 * @subpackage 2017-01
 * @since 1.0
 * @version 1.0
 */
global $cat;
    $cats = get_categories(array(
        'child_of' => $cat,
        'parent' => $cat,
        'hide_empty' => 0
    ));
    $c = get_category($cat);

get_header(); 
if(empty($cats)){
?>
	<div class="row">
		<div class="panel hlgd-title">
			<div class="panel-heading"><?php single_cat_title(); ?></div>
        	<hr>
            <div class="panel-body imgteaser">
	            	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
					    <?php if(!is_sticky()){?>
					    	<div class="col-md-3 photob">
				                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
				                    <?php the_post_thumbnail(array(250,120));?>
				                    <div class="bwidt">
				                        <span class="stxt">
				                            <?php the_title(); ?>
				                        </span>
				                    </div>
				                </a>
				            </div>
					<?php } endwhile;?>
				    <?php else: ?>
				        <div class="post"><p>文章稍后更新</p></div>
				    <?php endif; ?>
            </div>
			<?php wp_pagenavi(); ?>
		</div>
	</div>
	<?php
}else{
    foreach($cats as $the_cat){
        $posts = get_posts(array(
            'category' => $the_cat->cat_ID,
            'numberposts' => 10,
        ));
        if(!empty($posts)){
            echo '
            <div class="item cat_item">
                <div class="item_title"><h2><a title="'.$the_cat->name.'" href="'.get_category_link($the_cat).'">'.$the_cat->name.'</a></h2></div>  
                <ul class="box_list">';
                    foreach($posts as $post){
                        echo '<li><span class="alignright">'.mysql2date('Y-m-d', $post->post_date).'</span>
                        <a title="'.$post->post_title.'" href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>';
                    }
                echo '</ul>
            </div>';
        }
    }
}
?>
<?php get_footer(); ?>
